<link rel="stylesheet" href="<%- Virtual_Path.Static %>jquery.plugin/pagination/pagination.css">
<script src="<%- Virtual_Path.Static %>jquery.plugin/pagination/pagination.js"></script>
<div class="anchor-tab">
    <ul class="tab">
        <li><a href="/member/family/income">公会收入</a></li>
        <li class="on"><a href="/member/family/anchor">公会艺人</a></li>
        <!--<li><a href="/member/family/anchor_income">艺人收入</a></li>-->
        <!--<li><a href="/member/family/anchor_salary">基本工资</a></li>-->
        <li><a href="/member/family/anchor_live">直播数据</a></li>
    </ul>
</div>
<div class="anchor-cont">
    <div class="tabs-cont">
        <div class="hander-func">
            <p class="fl">
                用户ID：
                <input type="text" class="qing-input" placeholder="" id="J_FAnchor_ID" name="">
            </p>
            <p class="fl">
                艺人名称：
                <input type="text" class="qing-input" placeholder="" id="AnchorFNickName" name="">
            </p>
            <a id="J_find_family_anchor" class="c-button fl" href="javascript:;">查询</a>
        </div>
        <div class="tableinfo">
            <table class="tabinfo">
                <thead>
                <tr>
                    <th>艺人ID</th>
                    <th>艺人昵称</th>
                    <th>性别</th>
                    <th>直播类型</th>
                    <th>状态</th>
                </tr>
                </thead>
                <tbody id="J_OrderList">
                <tr>
                    <td colspan="6">加载中...</td>
                </tr>
                </tbody>
            </table>
        </div>
        <div id="AjaxPagination" class="pagination"></div>
    </div>
</div>
<script>
    $(function () {
        if (_PageData.Family_ID != _StateData.Family.Family_ID) {
            return;
        }
        var _ThisPage = {
            PageParm: {
                P_Get: true,
                Loading: false, //加载中
                Total: null,       //总条数
                MaxCode: "",    //MaxCode
                Start: 0,       //开始
                Length: 7      //页长度
            }
        };
        var param = {};
        //搜索
        $('#J_find_family_anchor').on('click', function () {

            _ThisPage = {
                PageParm: {
                    P_Get: true,
                    Loading: false, //加载中
                    Total: null,       //总条数
                    MaxCode: "",    //MaxCode
                    Start: 0,       //开始
                    Length: 7      //页长度
                }
            };
            param.User_ID = $.trim($('#J_FAnchor_ID').val());
            param.NickName = $.trim($('#AnchorFNickName').val());
            if (!(param.User_ID || param.NickName)) {
                $.KOC.Tips.Open("Error", '请输入用户名或昵称！', {Timeout: 2000});
                return;
            }
            AnchorData();
        });

        if (!(param.User_ID && param.NickName)) {
            AnchorData();
        }
        function AnchorData() {
            $.ajax({
                url: '/ajax/user.user-anchor.page',
                type: 'post',
                dataType: 'json',
                data: {
                    P_Get: _ThisPage.PageParm.P_Get,
                    P_Total: _ThisPage.PageParm.Total,
                    P_MaxCode: _ThisPage.PageParm.MaxCode,
                    iDisplayStart: _ThisPage.PageParm.Start,
                    iDisplayLength: _ThisPage.PageParm.Length,
                    Sort_Col: "Create_Date",
                    Sort_Dir: "DESC",
                    Family_ID: _PageData.Family_ID,
                    User_ID: param.User_ID,
                    NickName: param.NickName
                },
                success: function (data) {
                    _ThisPage.PageParm.Loading = false;
                    _ThisPage.PageParm.P_Get = false;
                    if (data.flag !== 0) {
                        $.KOC.Tips.Open("Error", data.msg + "(" + data.flag + ")", {Timeout: 3000});
                        return;
                    }
                    _ThisPage.PageParm.Total = data.iTotalRecords;
                    if (data.iTotalRecords > 0) {
                        $("#AjaxPagination").empty().pagination(data.iTotalRecords, {
                            num_edge_entries: 2, //边缘页数
                            num_display_entries: 5, //主体页数
                            callback: PageCallback,
                            items_per_page: _ThisPage.PageParm.Length, //每页显示1项
                            prev_text: "前一页",
                            next_text: "后一页"
                        });
                    } else {
                        var _html = RenderPage(null, data.iTotalRecords);
                        $("#AjaxPagination").empty();
                        $('#J_OrderList').empty().html(_html);
                    }
                }
            })
        }

        function PageCallback(id) {
            _ThisPage.PageParm.Start = id * _ThisPage.PageParm.Length;
            InitTable(id);
        }

        function InitTable(index) {
            $.ajax({
                url: '/ajax/user.user-anchor.page',
                type: 'post',
                dataType: 'json',
                data: {
                    P_Get: _ThisPage.PageParm.P_Get,
                    P_Total: _ThisPage.PageParm.Total,
                    P_MaxCode: _ThisPage.PageParm.MaxCode,
                    iDisplayStart: _ThisPage.PageParm.Start,
                    iDisplayLength: _ThisPage.PageParm.Length,
                    Sort_Col: "Create_Date",
                    Family_ID: _PageData.Family_ID,
                    Sort_Dir: "DESC",
                    User_ID: param.User_ID,
                    NickName: param.NickName
                },
                success: function (data) {
                    _ThisPage.PageParm.Loading = false;
                    _ThisPage.PageParm.P_Get = false;
                    if (data.flag !== 0) {
                        $.KOC.Tips.Open("Error", data.msg + "(" + data.flag + ")", {Timeout: 3000});
                        return;
                    }
                    _ThisPage.PageParm.Total = data.iTotalRecords;
                    _ThisPage.PageParm.MaxCode = data.sMaxCode;
                    _ThisPage.PageParm.Start += _ThisPage.PageParm.Length;
                    var _html = '';
                    if (_ThisPage.PageParm.Total > 0) {
                        _.forEach(data.aaData, function (ThisValue) {
                            _html += RenderPage(ThisValue);
                        });
                    }
                    $('#J_OrderList').empty().html(_html);
                }
            });
        }

        function RenderPage(ThisValue, len) {
            var _html = '';
            if (len <= 0) {
                _html += '<tr>' +
                        '<td colspan="6">' + '暂无数据！' +
                        '</td>' +
                        '</tr>';
            } else {
                var parm = {
                    state: '',
                    sexs: '',
                    lives: '',
                    rating: ''
                }
                switch (ThisValue.Anchor_Status) {
                    case 0:
                        parm.state = '正常';
                        break;
                    case 1:
                        parm.state = '封号';
                        break;
                    case 2:
                        parm.state = '申请中';
                        break;
                    case 3:
                        parm.state = '拒绝';
                        break;
                    default:
                        parm.state = '-';
                        break;
                }
                switch (ThisValue.Sex) {
                    case 1:
                        parm.sexs = '男';
                        break;
                    case 2:
                        parm.sexs = '女';
                        break;
                    default :
                        parm.sexs = '-';
                        break;
                }
                switch (ThisValue.Live) {
                    case 0:
                        parm.lives = '休息中';
                        break;
                    case 1:
                        parm.lives = '直播中';
                        break;
                    default :
                        parm.lives = '-';
                        break;
                }
                _html += '<tr>' +
                        '<td>' + ThisValue.User_ID +
                        '</td>' +
                        '<td>' + ThisValue.NickName +
                        '</td>' +
                        '<td>' + parm.sexs +
                        '</td>' +
                        '<td>' + parm.lives +
                        '</td>' +
                        '<td>' + parm.state +
                        '</td>' +
                        '</tr>';
            }
            return _html;
        }
    })
</script>